package org.example.old.converter;


import com.alibaba.excel.util.BooleanUtils;
import com.alibaba.excel.write.handler.CellWriteHandler;
import com.alibaba.excel.write.handler.context.CellWriteHandlerContext;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.common.usermodel.HyperlinkType;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CreationHelper;
import org.apache.poi.ss.usermodel.Hyperlink;

/**
 * 自定义拦截器，对第一行第一列超链接
 */
@Slf4j
public class CustomCellWriteHandler implements CellWriteHandler {
    @Override
    public void afterCellDispose(CellWriteHandlerContext context) {
         Cell cell = context.getCell();
         // 这里可以对cell操作
        log.info("第{}行，第{}列写入完成。",cell.getRowIndex(),cell.getColumnIndex());
        if(BooleanUtils.isTrue(context.getHead()) && cell.getColumnIndex() == 0){
            CreationHelper creationHelper = context.getWriteSheetHolder().getSheet()
                    .getWorkbook().getCreationHelper();
            Hyperlink hyperlink = creationHelper.createHyperlink(HyperlinkType.URL);
            hyperlink.setAddress("https://gitee.com/lxt0520/ProjectManager/blob/master/img/ceshi.PNG");
            cell.setHyperlink(hyperlink);
        }
    }
}
